<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title>转机联运管理</title>
    </head>
    <body>
        <div id="positionGrid" style="height:500px;" class="x-form-item">
        </div>
        <script>
            /*
             * Ext JS Library 2.0.2
             * Copyright(c) 2006-2008, Ext JS, LLC.
             * licensing@extjs.com
             *
             * http://extjs.com/license
             */
            Ext.onReady(function(){
                var positionCM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
                        header: '编号',
                        dataIndex: 'id',
                        hidden: true
                    }, {
                        header: '始发地',
                        dataIndex: 'from',
                        renderer: airportRender,
                        width: 100
                    }, {
                        header: '第一中转地',
                        dataIndex: 'mid',
                        renderer: airportRender,
                        width: 100
                    }, {
                        header: '第二中转地',
                        dataIndex: 'mid2',
                        renderer: airportRender,
                        width: 100
                    }, {
                        header: '目的地',
                        dataIndex: 'to',
                        renderer: airportRender,
                        width: 100
                    }, {
                        header: '第三中转地',
                        dataIndex: 'mid3',
                        renderer: airportRender,
                        width: 100
                    }, {
                        header: '第四中转地',
                        dataIndex: 'mid4',
                        renderer: airportRender,
                        width: 100
                    }, {
                        header: '终到地',
                        dataIndex: 'end',
                        renderer: airportRender,
                        width: 100
                    }, {
                        header: '航空公司',
                        dataIndex: 'airways_name',
                        width: 60
                    }, {
                        header: '生效日期',
                        dataIndex: 'start_date',
                        width: 70
                    }, {
                        header: '失效日期',
                        dataIndex: 'end_date',
                        width: 70
                    }, {
                        header: '舱位',
                        dataIndex: 'position',
                        width: 50
                    }, {
                        header: '舱位2',
                        dataIndex: 'position2',
                        width: 50
                    }, {
                        header: '舱位3',
                        dataIndex: 'position3',
                        width: 50
                    }, {
                        header: '舱位4',
                        dataIndex: 'position4',
                        width: 50
                    }, {
                        header: '价格',
                        dataIndex: 'price',
                        width: 50
                    }, {
                        header: '类型',
                        dataIndex: 'trip_type',
                        width: 60
                    }, {
                        header: '代理费率',
                        dataIndex: 'rake_off',
                        width: 60
                    }, {
                        header: '是否启用',
                        dataIndex: 'is_closed',
                        renderer: closedRender,
                        width: 60
                    }, {
                        header: '政策',
                        dataIndex: 'policy',
                        width: 120
                    }]);
                positionCM.defaultSortable = true;
                var positionDS = new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: '/admin/getAllZjlyPrice'
                    }),
                    reader: new Ext.data.JsonReader({
                        root: 'root'
                    }, [{
                            name: 'id'
                        }, {
                            name: 'from',
                            mapping: 'from_airport.airport_name'
                        }, {
                            name: 'mid',
                            mapping: 'mid_airport.airport_name'
                        }, {
                            name: 'mid2',
                            mapping: 'mid_airport2.airport_name'
                        }, {
                            name: 'to',
                            mapping: 'to_airport.airport_name'
                        }, {
                            name: 'mid3',
                            mapping: 'mid_airport3.airport_name'
                        }, {
                            name: 'mid4',
                            mapping: 'mid_airport4.airport_name'
                        }, {
                            name: 'end',
                            mapping: 'end_airport.airport_name'
                        }, {
                            name: 'airways_name',
                            mapping: 'airways.airways_name'
                        }, {
                            name: 'start_date'
                        }, {
                            name: 'end_date'
                        }, {
                            name: 'position'
                        }, {
                            name: 'position2'
                        }, {
                            name: 'position3'
                        }, {
                            name: 'position4'
                        }, {
                            name: 'price'
                        }, {
                            name: 'trip_type'
                        }, {
                            name: 'rake_off'
                        }, {
                            name: 'is_closed'
                        }, {
                            name: 'policy'
                        }])
                });
                /************************************************************
                 * Define menubar now in here
                 *   add and delete functions
                 ************************************************************/
                var menubar = [{
                        text: '添加政策',
                        tooltip: '添加政策',
                        iconCls: 'addItem',
                        handler: function(){
                            Create(positionDS);
                        }
                    }, '-', {
                        text: '删除政策',
                        tooltip: '删除政策',
                        iconCls: 'remove',
                        handler: function(){
                            Delete(positionDS, positionGridPanel);
                        }
                    }, '-', {
                        text: '编辑政策',
                        tooltip: '编辑政策',
                        iconCls: 'editItem',
                        handler: function(){
                            Edit(positionDS, positionGridPanel);
                        }
                    }];
                var positionGridPanel = new Ext.grid.GridPanel({
                    el: 'positionGrid',
                    ds: positionDS,
                    cm: positionCM,
                    collapsible: true,
                    animCollapse: false,
                    title: '转机联运',
                    tbar: menubar,
                    loadMask: true
                    //,clicksToEdit: 1
                });
                positionGridPanel.render();
                positionDS.load();

                function airportRender(value){
                    if (value.indexOf(" ")>0){
                        return value.substring(value.indexOf(" ")+1);
                    }else{
                        return value;
                    }
                }
                function closedRender(value){
                    if (value=="0"){
                        return "已经启用";
                    }else{
                        return "已经关闭";
                    }
                }
                //------------------------- 具体操作 ---------------------------------
                var from_id;
                var mid_id;
                var mid_id2;
                var to_id;
                var mid_id3;
                var mid_id4;
                var end_id;
                var airways;
                var from_airport;
                var mid_airport;
                var mid_airport2;
                var to_airport;
                var mid_airport3;
                var mid_airport4;
                var end_airport;
                var start_date;
                var end_date;
                var position;
                var position2;
                var position3;
                var position4;
                var price;
                var price2;
                var rake_off;
                var policy;
                var trip_type;
                var runRadio;
                var closeRadio;
                var airportTpl = new Ext.XTemplate('<tpl for="."><div class="search-item">','{airport_name}({airport_code})','</div></tpl>');
                var airportStore = new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: "/admin/getAllAirportComboBox"
                    }),
                    reader: new Ext.data.JsonReader({
                        root: 'root'
                    }, ['id','airport_name','airport_code'])
                });

                function init(){
                    from_airport = new Ext.form.ComboBox({
                        store: airportStore,
                        fieldLabel: '始发地',
                        name: 'from_airport',
                        allowBlank: false,
                        blankText: "始发地必须选择",
                        typeAhead: false,
                        loadingText: '正在查找...',
                        //width: 230,
                        anchor: '90%',
                        //pageSize: 10,
                        tpl: airportTpl,
                        minChars: 0,
                        itemSelector: 'div.search-item',
                        onSelect: function(record){
                            from_airport.setValue(record.data.airport_name);
                            from_id.setValue(record.data.id);
                            if (trip_type.getValue()=="往返"){
                                to_airport.setValue(record.data.airport_name);
                                to_id.setValue(record.data.id);
                            }
                            else if (trip_type.getValue()=="联程往返"){
                                end_airport.setValue(record.data.airport_name);
                                end_id.setValue(record.data.id);
                            }
                            if (this.isExpanded()) {
                                this.collapse();
                            }
                        }
                    });
                    mid_airport = new Ext.form.ComboBox({
                        store: airportStore,
                        fieldLabel: '中转地',
                        name: 'mid_airport',
                        allowBlank: false,
                        blankText: "中转地必须选择",
                        typeAhead: false,
                        loadingText: '正在查找...',
                        //width: 230,
                        anchor: '90%',
                        //pageSize: 10,
                        hideTrigger: false,
                        tpl: airportTpl,
                        minChars: 0,
                        itemSelector: 'div.search-item',
                        onSelect: function(record){
                            mid_airport.setValue(record.data.airport_name);
                            mid_id.setValue(record.data.id);
                            if (this.isExpanded()) {
                                this.collapse();
                            }
                        }
                    });
                    mid_airport2 = new Ext.form.ComboBox({
                        store: airportStore,
                        fieldLabel: '中转地2',
                        name: 'mid_airport2',
                        allowBlank: true,
                        typeAhead: false,
                        loadingText: '正在查找...',
                        //width: 230,
                        anchor: '90%',
                        //pageSize: 10,
                        hideTrigger: false,
                        tpl: airportTpl,
                        minChars: 0,
                        itemSelector: 'div.search-item',
                        onSelect: function(record){
                            mid_airport2.setValue(record.data.airport_name);
                            mid_id2.setValue(record.data.id);
                            if (this.isExpanded()) {
                                this.collapse();
                            }
                        }
                    });
                    to_airport = new Ext.form.ComboBox({
                        store: airportStore,
                        fieldLabel: '目的地',
                        name: 'to_airport',
                        allowBlank: false,
                        blankText: "目的地必须选择",
                        displayField: 'airport_name',
                        valueField: 'id',
                        typeAhead: false,
                        loadingText: '正在查找...',
                        //width: 230,
                        anchor: '90%',
                        //pageSize: 10,
                        hideTrigger: false,
                        tpl: airportTpl,
                        minChars: 0,
                        itemSelector: 'div.search-item',
                        onSelect: function(record){
                            to_airport.setValue(record.data.airport_name);
                            to_id.setValue(record.data.id);
                            //if (from_id.getValue()==to_id.getValue()){
                            //    trip_type.setValue("往返");
                            //    trip_type.disable();
                            //}else{
                            //    trip_type.setValue("联程");
                            //    trip_type.enable();
                            //}
                            if (this.isExpanded()) {
                                this.collapse();
                            }
                        }
                    });
                    mid_airport3 = new Ext.form.ComboBox({
                        store: airportStore,
                        fieldLabel: '中转地3',
                        name: 'mid_airport3',
                        allowBlank: true,
                        blankText: "中转地3必须选择",
                        typeAhead: false,
                        loadingText: '正在查找...',
                        //width: 230,
                        anchor: '90%',
                        //pageSize: 10,
                        hideTrigger: false,
                        tpl: airportTpl,
                        minChars: 0,
                        itemSelector: 'div.search-item',
                        onSelect: function(record){
                            mid_airport3.setValue(record.data.airport_name);
                            mid_id3.setValue(record.data.id);
                            if (this.isExpanded()) {
                                this.collapse();
                            }
                        }
                    });
                    mid_airport4 = new Ext.form.ComboBox({
                        store: airportStore,
                        fieldLabel: '中转地4',
                        name: 'mid_airport4',
                        allowBlank: true,
                        typeAhead: false,
                        loadingText: '正在查找...',
                        //width: 230,
                        anchor: '90%',
                        //pageSize: 10,
                        hideTrigger: false,
                        tpl: airportTpl,
                        minChars: 0,
                        itemSelector: 'div.search-item',
                        onSelect: function(record){
                            mid_airport4.setValue(record.data.airport_name);
                            mid_id4.setValue(record.data.id);
                            if (this.isExpanded()) {
                                this.collapse();
                            }
                        }
                    });
                    end_airport = new Ext.form.ComboBox({
                        store: airportStore,
                        fieldLabel: '终到地',
                        name: 'end_airport',
                        allowBlank: true,
                        blankText: "终到地必须选择",
                        typeAhead: false,
                        loadingText: '正在查找...',
                        //width: 230,
                        anchor: '90%',
                        //pageSize: 10,
                        hideTrigger: false,
                        tpl: airportTpl,
                        minChars: 0,
                        itemSelector: 'div.search-item',
                        onSelect: function(record){
                            end_airport.setValue(record.data.airport_name);
                            end_id.setValue(record.data.id);
                            if (this.isExpanded()) {
                                this.collapse();
                            }
                        }
                    });
                    from_id = new Ext.form.Hidden({
                        name: 'from_id'
                    });
                    mid_id = new Ext.form.Hidden({
                        name: 'mid_id'
                    });
                    mid_id2 = new Ext.form.Hidden({
                        name: 'mid_id2'
                    });
                    mid_id3 = new Ext.form.Hidden({
                        name: 'mid_id3'
                    });
                    mid_id4 = new Ext.form.Hidden({
                        name: 'mid_id4'
                    });
                    to_id = new Ext.form.Hidden({
                        name: 'to_id'
                    });
                    end_id = new Ext.form.Hidden({
                        name: 'end_id'
                    });
                    airways = new Ext.form.ComboBox({
                        store: new Ext.data.Store({
                            proxy: new Ext.data.HttpProxy({
                                url: '/admin/getInternalAirways'
                            }),
                            reader: new Ext.data.JsonReader({
                                root: 'root'
                            }, ['id', 'airways_code', 'airways_name'])
                        }),
                        name: 'airways',
                        loadingText: '正在加载...',
                        //displayField: 'customer_type',
                        displayField: 'airways_name',
                        valueField: 'id',
                        mode: 'remote',
                        triggerAction: 'all',
                        hiddenName: 'airways',//如果不想提交displayField，则在这儿指定以提交ID的值．
                        //hiddenId:'type_id',
                        fieldLabel: '航空公司',
                        emptyText: '请选择...',
                        editable: false,
                        allowBlank: false,
                        width: 100,
                        //maxHeight: 150,
                        tabIndex: 4
                    });
                    start_date = new Ext.form.DateField({
                        fieldLabel: '起始日期',
                        name: 'start_date',
                        altFormats: 'Y-m-d',
                        format: 'Y-m-d', //格式化日期
                        //disabledDays: [0,6],	//不让选择周六，周日
                        //disabledDaysText: "周末要休息",
                        invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
                        allowBlank: false,
                        //emptyText: '请选择...',
                        inputType: '2008-01-01',
                        width: 90
                    });
                    end_date = new Ext.form.DateField({
                        fieldLabel: '结束日期',
                        name: 'end_date',
                        altFormats: 'Y-m-d',
                        format: 'Y-m-d', //格式化日期
                        //disabledDays: [0,6],	//不让选择周六，周日
                        //disabledDaysText: "周末要休息",
                        invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
                        allowBlank: false,
                        //emptyText: '请选择...',
                        inputType: '2008-01-01',
                        width: 90
                    });
                    position = new Ext.form.TextField({
                        fieldLabel: '舱位',
                        allowBlank: false,
                        blankText: "舱位不能为空",
                        name: 'position',
                        anchor: '80%'
                    });
                    position2 = new Ext.form.TextField({
                        fieldLabel: '舱位2',
                        allowBlank: false,
                        blankText: "舱位2不能为空",
                        name: 'position2',
                        anchor: '80%'
                    });
                    position3 = new Ext.form.TextField({
                        fieldLabel: '舱位3',
                        allowBlank: true,
                        blankText: "舱位3不能为空",
                        name: 'position3',
                        anchor: '80%'
                    });
                    position4 = new Ext.form.TextField({
                        fieldLabel: '舱位4',
                        allowBlank: true,
                        blankText: "舱位4不能为空",
                        name: 'position4',
                        anchor: '80%'
                    });
                    price = new Ext.form.NumberField({
                        fieldLabel: '价格',
                        allowBlank: false,
                        blankText: "价格不能为空",
                        name: 'price',
                        anchor: '90%'
                    });
                    price2 = new Ext.form.NumberField({
                        fieldLabel: '往返价格',
                        allowBlank: true,
                        blankText: "往返价格不能为空",
                        name: 'price2',
                        anchor: '90%'
                    });
                    rake_off = new Ext.form.NumberField({
                        fieldLabel: '代理费率',
                        allowBlank: false,
                        blankText: "代理费率不能为空",
                        name: 'rake_off',
                        value: 3,
                        anchor: '90%'
                    });
                    policy = new Ext.form.TextArea({
                        fieldLabel: '退改签',
                        allowBlank: true,
                        name: 'policy',
                        height: 40,
                        anchor: '90%'
                    });
                    trip_type = new Ext.form.ComboBox({
                        store: new Ext.data.Store({
                            reader: new Ext.data.ArrayReader({}, ['value']),
                            data: [['联程'], ['往返'], ['联程往返']]
                        }),
                        name: 'trip_type',
                        fieldLabel: '航程类型',
                        resiable: true,
                        typeAhead: true,
                        width: 100,
                        handleHeight: 100,
                        displayField: 'value',
                        valueField: 'value',
                        nameField: 'trip_type',
                        selectOnFocus: true,
                        mode: 'local',
                        selectOnFocus: true,
                        triggerAction: 'all', //这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
                        readOnly: true,
                        emptyText: '',
                        allowBlank: true,
                        value: '联程',
                        onSelect: function(record){
                            //alert(record.data.value);
                            trip_type.setValue(record.data.value);
                            if (record.data.value=="联程"){
                                Ext.getCmp('position3_div').hide();
                                Ext.getCmp('mid_airport_div').hide();
                                Ext.getCmp('end_airport_div').hide();
                                mid_airport3.allowBlank=true;
                                end_airport.allowBlank=true;
                                position3.allowBlank=true;
                                position4.allowBlank=true;
                                price2.enable();
                            }
                            else if (record.data.value=="往返"){
                                Ext.getCmp('position3_div').hide();
                                Ext.getCmp('mid_airport_div').hide();
                                Ext.getCmp('end_airport_div').hide();
                                mid_airport3.allowBlank=true;
                                end_airport.allowBlank=true;
                                position3.allowBlank=true;
                                position4.allowBlank=true;
                                price2.disable();
                            }
                            else{
                                Ext.getCmp('position3_div').show();
                                Ext.getCmp('mid_airport_div').show();
                                Ext.getCmp('end_airport_div').show();
                                mid_airport3.allowBlank=false;
                                end_airport.allowBlank=false;
                                position3.allowBlank=false;
                                position4.allowBlank=false;
                                price2.disable();
                            }
                            if (this.isExpanded()) {
                                this.collapse();
                            }
                        }
                    });
                    runRadio = new Ext.form.Radio({
                        fieldLabel: '是否启用',
                        name: 'is_closed',
                        boxLabel: '启用',
                        checked: true,
                        inputValue: '0'
                    });
                    closeRadio = new Ext.form.Radio({
                        name: 'is_closed',
                        boxLabel: '关闭',
                        checked: false,
                        hideLabel: true,
                        inputValue: '1'
                    });
                }
                //---------------------Create Position------------------------
                function Create(dataStore){
                    init();

                    var formPanel = new Ext.form.FormPanel({
                        //baseCls: 'x-plain',
                        labelWidth: 55,
                        labelAlign: 'right',
                        frame: true,
                        url: '/admin/addZjlyPrice',
                        items: [{
                                layout: 'column',
                                items: [{
                                        columnWidth: .4,
                                        layout: 'form',
                                        items: [from_airport]
                                    }, {
                                        columnWidth: .4,
                                        layout: 'form',
                                        items: [trip_type]
                                    }, {
                                        columnWidth: .2,
                                        layout: 'form',
                                        items: [position]
                                    }]
                            },{
                                layout: 'column',
                                items: [{
                                        columnWidth: .4,
                                        layout: 'form',
                                        items: [mid_airport]
                                    }, {
                                        columnWidth: .4,
                                        layout: 'form',
                                        items: [mid_airport2]
                                    }, {
                                        columnWidth: .2,
                                        layout: 'form',
                                        items: [position2]
                                    }]
                            },{
                                layout: 'column',
                                items: [{
                                        columnWidth: .4,
                                        layout: 'form',
                                        items: [to_airport]
                                    }, {
                                        columnWidth: .4,
                                        layout: 'form',
                                        items: [airways]
                                    }, {
                                        id: 'position3_div',
                                        columnWidth: .2,
                                        layout: 'form',
                                        items: [position3]
                                    }]
                            },{
                                id: 'mid_airport_div',
                                layout: 'column',
                                items: [{
                                        columnWidth: .4,
                                        layout: 'form',
                                        items: [mid_airport3]
                                    }, {
                                        columnWidth: .4,
                                        layout: 'form',
                                        items: [mid_airport4]
                                    }, {
                                        columnWidth: .2,
                                        layout: 'form',
                                        items: [position4]
                                    }]
                            },{
                                layout: 'column',
                                items: [{
                                        id: 'end_airport_div',
                                        columnWidth: .4,
                                        layout: 'form',
                                        items: [end_airport]
                                    }, {
                                        columnWidth: .3,
                                        layout: 'form',
                                        items: [start_date]
                                    }, {
                                        columnWidth: .3,
                                        layout: 'form',
                                        items: [end_date]
                                    }]
                            },{
                                layout: 'column',
                                items: [{
                                        columnWidth: .2,
                                        layout: 'form',
                                        items: [price]
                                    }, {
                                        columnWidth: .2,
                                        layout: 'form',
                                        items: [price2]
                                    }, {
                                        columnWidth: .2,
                                        layout: 'form',
                                        items: [rake_off]
                                    }, {
                                        columnWidth: .4,
                                        layout: 'form',
                                        items: [{
                                                layout: 'column',
                                                items: [{
                                                        columnWidth: .5,
                                                        layout: 'form',
                                                        items: [runRadio]
                                                    }, {
                                                        columnWidth: .5,
                                                        layout: 'form',
                                                        items: [closeRadio]
                                                    }]
                                            }]
                                    }]
                            }, policy, from_id, mid_id, mid_id2, to_id, mid_id3, mid_id4, end_id]
                    });

                    // define window and show it in desktop
                    var window = new Ext.Window({
                        title: '添加转机联运',
                        width: 660,
                        height: 300,
                        //minWidth: 300,
                        //minHeight: 300,
                        layout: 'fit',
                        plain: true,
                        bodyStyle: 'padding:5px;',
                        buttonAlign: 'center',
                        items: formPanel,
                        modal: true,
                        buttons: [{
                                text: '增加',
                                handler: function(){
                                    // check form value
                                    if (formPanel.form.isValid()) {
                                        if (from_id.getValue() == "") {
                                            Ext.MessageBox.alert('提示', '请选择始发地');
                                        }
                                        else if (mid_id.getValue() == "") {
                                            Ext.MessageBox.alert('提示', '请选择中转地');
                                        }
                                        else if (to_id.getValue() == "") {
                                            Ext.MessageBox.alert('提示', '请选择终到地');
                                        }
                                        else {
                                            formPanel.form.submit({
                                                waitMsg: 'In processing',
                                                success: function(form, action){
                                                    var info = "";
                                                    if (action && action.result) {
                                                        info = action.result.info;
                                                    }
                                                    else {
                                                        info = '提交失败,具体失败原因请查询日志文件';
                                                    }
                                                    if (info.indexOf("成功")>=0){
                                                        Ext.MessageBox.alert('操作成功', info);
                                                        window.destroy();
                                                        dataStore.load();
                                                    }else{
                                                        Ext.MessageBox.alert('操作失败', info);
                                                    }
                                                },
                                                failure: function(form, action){
                                                    Ext.MessageBox.alert('操作失败', '提交失败');
                                                }
                                            });
                                        }

                                    }
                                    //else {
                                    //    Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                                    //}
                                }
                            }, {
                                text: '取消',
                                handler: function(){
                                    window.destroy();
                                }
                            }]
                    });
                    window.show();

                    Ext.getCmp('position3_div').hide();
                    Ext.getCmp('mid_airport_div').hide();
                    Ext.getCmp('end_airport_div').hide();
                };
                //----------------Delete Position--------------------------
                function Delete(dataStore, gridPanel){
                    // get the selected items
                    var m = gridPanel.getSelections();
                    if (m.length > 0) {
                        Ext.MessageBox.confirm('提示', '你真的要删除这条记录吗？', function(btn){
                            if (btn == 'yes') {
                                var jsonData = "[";
                                for (var i = 0; i < m.length; i++) {
                                    var ss = "{\"id\":\"" + m[i].get("id") + "\"}";
                                    if (i == 0) {
                                        jsonData = jsonData + ss;
                                    }
                                    else {
                                        jsonData = jsonData + "," + ss;
                                    }
                                    dataStore.remove(m[i]);
                                }
                                jsonData = jsonData + "]";
                                //Ext.MessageBox.alert(jsonData);
                                dataStore.load({
                                    params: {
                                        delData: jsonData
                                    }
                                });
                            }
                        });
                    }
                    else {
                        Ext.MessageBox.alert('错误提示', '请先选择要删除的记录');
                    }
                };

                //------------Edit Position-----------------
                function Edit(dataStore, gridPanel){
                    var m = gridPanel.getSelections();
                    if (m.length > 0 && m.length == 1) {
                        init();

                        var selectedId = m[0].get("id");
                        var editFormPanel = new Ext.form.FormPanel({
                            //baseCls: 'x-plain',
                            labelWidth: 55,
                            labelAlign: 'right',
                            frame: true,
                            url: '/admin/editZjlyPrice?id=' + selectedId,
                            reader: new Ext.data.JsonReader({
                                root: 'root'
                            }, ['id', {
                                    name: 'from_airport',
                                    mapping: 'from_airport.airport_name'
                                }, {
                                    name: 'mid_airport',
                                    mapping: 'mid_airport.airport_name'
                                }, {
                                    name: 'mid_airport2',
                                    mapping: 'mid_airport2.airport_name'
                                }, {
                                    name: 'to_airport',
                                    mapping: 'to_airport.airport_name'
                                }, {
                                    name: 'mid_airport3',
                                    mapping: 'mid_airport3.airport_name'
                                }, {
                                    name: 'mid_airport4',
                                    mapping: 'mid_airport4.airport_name'
                                }, {
                                    name: 'end_airport',
                                    mapping: 'end_airport.airport_name'
                                }, {
                                    name: 'airways',
                                    mapping: 'airways.airways_name'
                                }, {
                                    name: 'start_date',
                                    type: 'date',
                                    dateFormat: 'Y/m/d'
                                }, {
                                    name: 'end_date',
                                    type: 'date',
                                    dateFormat: 'Y/m/d'
                                }, 'position', 'position2', 'position3', 'position4', 'price', 'trip_type', 'rake_off', 'is_closed', 'policy']),
                            items: [{
                                    layout: 'column',
                                    items: [{
                                            columnWidth: .4,
                                            layout: 'form',
                                            items: [from_airport]
                                        }, {
                                            columnWidth: .4,
                                            layout: 'form',
                                            items: [trip_type]
                                        }, {
                                            columnWidth: .2,
                                            layout: 'form',
                                            items: [position]
                                        }]
                                },{
                                    layout: 'column',
                                    items: [{
                                            columnWidth: .4,
                                            layout: 'form',
                                            items: [mid_airport]
                                        }, {
                                            columnWidth: .4,
                                            layout: 'form',
                                            items: [mid_airport2]
                                        }, {
                                            columnWidth: .2,
                                            layout: 'form',
                                            items: [position2]
                                        }]
                                },{
                                    layout: 'column',
                                    items: [{
                                            columnWidth: .4,
                                            layout: 'form',
                                            items: [to_airport]
                                        }, {
                                            columnWidth: .4,
                                            layout: 'form',
                                            items: [airways]
                                        }, {
                                            id: 'position3_div',
                                            columnWidth: .2,
                                            layout: 'form',
                                            items: [position3]
                                        }]
                                },{
                                    id: 'mid_airport_div',
                                    layout: 'column',
                                    items: [{
                                            columnWidth: .4,
                                            layout: 'form',
                                            items: [mid_airport3]
                                        }, {
                                            columnWidth: .4,
                                            layout: 'form',
                                            items: [mid_airport4]
                                        }, {
                                            columnWidth: .2,
                                            layout: 'form',
                                            items: [position4]
                                        }]
                                },{
                                    layout: 'column',
                                    items: [{
                                            id: 'end_airport_div',
                                            columnWidth: .4,
                                            layout: 'form',
                                            items: [end_airport]
                                        }, {
                                            columnWidth: .3,
                                            layout: 'form',
                                            items: [start_date]
                                        }, {
                                            columnWidth: .3,
                                            layout: 'form',
                                            items: [end_date]
                                        }]
                                },{
                                    layout: 'column',
                                    items: [{
                                            columnWidth: .3,
                                            layout: 'form',
                                            items: [price]
                                        }, {
                                            columnWidth: .3,
                                            layout: 'form',
                                            items: [rake_off]
                                        }, {
                                            columnWidth: .4,
                                            layout: 'form',
                                            items: [{
                                                    layout: 'column',
                                                    items: [{
                                                            columnWidth: .5,
                                                            layout: 'form',
                                                            items: [runRadio]
                                                        }, {
                                                            columnWidth: .5,
                                                            layout: 'form',
                                                            items: [closeRadio]
                                                        }]
                                                }]
                                        }]
                                }, policy, from_id, mid_id, mid_id2, to_id, mid_id3, mid_id4, end_id]
                        });

                        editFormPanel.form.load({
                            url: '/admin/getZjlyPriceByID?id=' + selectedId,
                            waitMsg: '正在载入数据...',
                            success: function(form, action){
                                //Ext.MessageBox.alert('提示信息', '信息加载成功！');
                                //alert(trip_type.getValue());
                                if (trip_type.getValue()=="联程" || trip_type.getValue()=="往返"){
                                    Ext.getCmp('position3_div').hide();
                                    Ext.getCmp('mid_airport_div').hide();
                                    Ext.getCmp('end_airport_div').hide();
                                    mid_airport3.allowBlank=true;
                                    end_airport.allowBlank=true;
                                    position3.allowBlank=true;
                                    position4.allowBlank=true;
                                }else{
                                    mid_airport3.allowBlank=false;
                                    end_airport.allowBlank=false;
                                    position3.allowBlank=false;
                                    position4.allowBlank=false;
                                }
                            },
                            failure: function(form, action){
                                Ext.MessageBox.alert('提示信息', '信息加载失败');
                            }
                        });

                        var editWindow = new Ext.Window({
                            title: '编辑仓位',
                            width: 660,
                            height: 300,
                            //minWidth: 300,
                            //minHeight: 300,
                            layout: 'fit',
                            plain: true,
                            bodyStyle: 'padding:5px;',
                            buttonAlign: 'center',
                            items: editFormPanel,
                            modal: true,
                            buttons: [{
                                    text: '提交',
                                    handler: function(){
                                        // check form value
                                        if (editFormPanel.form.isValid()) {

                                            editFormPanel.form.submit({
                                                waitMsg: '处理过程中...',
                                                success: function(form, action){
                                                    var info = "";
                                                    if (action && action.result) {
                                                        info = action.result.info;
                                                    }
                                                    else {
                                                        info = '提交失败,具体失败原因请查询日志文件';
                                                    }
                                                    if (info.indexOf("成功")>=0){
                                                        Ext.MessageBox.alert('操作成功', info);
                                                        editWindow.hide();
                                                        dataStore.load();
                                                    }else{
                                                        Ext.MessageBox.alert('操作失败', info);
                                                    }
                                                },
                                                failure: function(form, action){
                                                    Ext.MessageBox.alert('操作失败', '提交失败');
                                                }
                                            });

                                        }
                                        else {
                                            Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                                        }
                                    }
                                }, {
                                    text: '取消',
                                    handler: function(){
                                        editWindow.hide();
                                    }
                                }]
                        });
                        editWindow.show();

                    }
                    else {
                        Ext.MessageBox.alert('提示', "请先选择一条要编辑记录");
                    }
                }

            });
        </script>
    </body>
</html>
